<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>欢迎登录 | 系统名称</title>
    <!-- Bootstrap 5 CSS -->
    <link href="/static/vendor/bootstrap/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome 图标 -->
    <link rel="stylesheet" href="/static/vendor/font-awesome/all.min.css">
    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <style>
        :root {
            --primary-color: #4361ee;
            --secondary-color: #3f37c9;
            --light-color: #f8f9fa;
            --dark-color: #212529;
            --success-color: #4cc9f0;
            --error-color: #f72585;
        }
        
        body {
            font-family: 'Noto Sans SC', sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            background-size: cover;
            background-position: center;
            position: relative;
            overflow: hidden;
        }
        
        body::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(255, 255, 255, 0.3);
            z-index: -1;
        }
        
        .login-container {
            width: 100%;
            max-width: 420px;
            background: white;
            border-radius: 16px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            overflow: hidden;
            transition: all 0.3s ease;
            position: relative;
        }
        
        .login-container:hover {
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.15);
            transform: translateY(-5px);
        }
        
        .login-header {
            background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
            color: white;
            padding: 30px 20px;
            text-align: center;
        }
        
        .login-header h2 {
            font-weight: 700;
            margin-bottom: 5px;
        }
        
        .login-header p {
            opacity: 0.8;
            font-size: 0.9rem;
        }
        
        .login-body {
            padding: 30px;
        }
        
        .form-floating label {
            color: #6c757d;
            font-weight: 400;
        }
        
        .form-control {
            height: 50px;
            border-radius: 8px;
            border: 1px solid #e0e0e0;
            transition: all 0.3s;
        }
        
        .form-control:focus {
            box-shadow: 0 0 0 0.25rem rgba(67, 97, 238, 0.25);
            border-color: var(--primary-color);
        }
        
        .btn-login {
            background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
            border: none;
            height: 50px;
            font-weight: 500;
            letter-spacing: 1px;
            border-radius: 8px;
            transition: all 0.3s;
        }
        
        .btn-login:hover {
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(67, 97, 238, 0.3);
        }
        
        .divider {
            display: flex;
            align-items: center;
            margin: 20px 0;
            color: #6c757d;
            font-size: 0.8rem;
        }
        
        .divider::before, .divider::after {
            content: "";
            flex: 1;
            border-bottom: 1px solid #e0e0e0;
        }
        
        .divider::before {
            margin-right: 10px;
        }
        
        .divider::after {
            margin-left: 10px;
        }
        
        .social-login {
            display: flex;
            justify-content: center;
            gap: 15px;
            margin-bottom: 20px;
        }
        
        .social-btn {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            transition: all 0.3s;
        }
        
        .social-btn:hover {
            transform: translateY(-3px);
        }
        
        .facebook {
            background-color: #3b5998;
        }
        
        .google {
            background-color: #db4437;
        }
        
        .github {
            background-color: #333;
        }
        
        .login-footer {
            text-align: center;
            margin-top: 20px;
            font-size: 0.9rem;
            color: #6c757d;
        }
        
        .login-footer a {
            color: var(--primary-color);
            text-decoration: none;
            font-weight: 500;
        }
        
        .login-footer a:hover {
            text-decoration: underline;
        }
        
        /* 动画效果 */
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        .animate-fadein {
            animation: fadeIn 0.6s ease forwards;
        }
        
        /* 消息提示样式 */
        .alert-message {
            border-radius: 8px;
            padding: 12px 15px;
            margin-bottom: 20px;
            display: none;
        }
        
        .success {
            background-color: rgba(76, 201, 240, 0.1);
            border: 1px solid rgba(76, 201, 240, 0.3);
            color: #0a9396;
        }
        
        .error {
            background-color: rgba(247, 37, 133, 0.1);
            border: 1px solid rgba(247, 37, 133, 0.3);
            color: #f72585;
        }
        
        /* 响应式调整 */
        @media (max-width: 576px) {
            .login-container {
                margin: 20px;
                max-width: calc(100% - 40px);
            }
            
            .login-body {
                padding: 25px;
            }
        }
    </style>
</head>
<body>
    <div class="login-container animate-fadein">
        <div class="login-header">
            <h2><i class="fas fa-user-shield me-2"></i>欢迎回来</h2>
            <p>请输入您的凭证以访问您的帐户</p>
        </div>
        
        <div class="login-body">
            <div id="alertMessage" class="alert-message"></div>
            
            <form id="loginForm">
                <div class="form-floating mb-3">
                    <input type="text" class="form-control" id="username" placeholder="用户名/邮箱" required>
                    <label for="username"><i class="fas fa-user me-2"></i>用户名/邮箱</label>
                </div>
                
                <div class="form-floating mb-3">
                    <input type="password" class="form-control" id="password" placeholder="密码" required>
                    <label for="password"><i class="fas fa-lock me-2"></i>密码</label>
                </div>
                
                <div class="d-flex justify-content-between align-items-center mb-3">
                    <div class="form-check">
                        <input class="form-check-input" type="checkbox" id="rememberMe">
                        <label class="form-check-label" for="rememberMe">记住我</label>
                    </div>
                    <a href="#" class="text-decoration-none" style="color: var(--primary-color);">忘记密码?</a>
                </div>
                
                <button type="submit" class="btn btn-login w-100 mb-3">
                    <span id="loginText">登录</span>
                    <span id="loginSpinner" class="spinner-border spinner-border-sm" role="status" aria-hidden="true" style="display: none;"></span>
                </button>
                
                <div class="divider">或使用社交账号登录</div>
                
                <div class="social-login mb-4">
                    <a href="#" class="social-btn facebook"><i class="fab fa-facebook-f"></i></a>
                    <a href="#" class="social-btn google"><i class="fab fa-google"></i></a>
                    <a href="#" class="social-btn github"><i class="fab fa-github"></i></a>
                </div>
                
                <div class="login-footer">
                    还没有账号? <a href="#">立即注册</a>
                </div>
            </form>
        </div>
    </div>

    <!-- Bootstrap JS Bundle with Popper -->
    <script src="/static/vendor/bootstrap/bootstrap.bundle.min.js"></script>
    
    <!-- 自定义JS -->
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const loginForm = document.getElementById('loginForm');
            const alertMessage = document.getElementById('alertMessage');
            const loginText = document.getElementById('loginText');
            const loginSpinner = document.getElementById('loginSpinner');
            
            // 检查用户是否已登录
            function checkAuth() {
                fetch('/api/check-auth/', {
                    credentials: 'include'
                })
                .then(response => response.json())
                .then(data => {
                    if (data.isAuthenticated) {
                        showMessage('您已登录，正在跳转...', 'success');
                        setTimeout(() => {
                            window.location.href = '/index.html';
                        }, 500);
                    }
                });
            }
            
            // 显示消息提示
            function showMessage(message, type) {
                alertMessage.textContent = message;
                alertMessage.className = `alert-message ${type}`;
                alertMessage.style.display = 'block';
                
                // 5秒后自动消失
                setTimeout(() => {
                    alertMessage.style.display = 'none';
                }, 5000);
            }
            
            // 登录表单提交
            loginForm.addEventListener('submit', function(e) {
                e.preventDefault();
                
                const username = document.getElementById('username').value;
                const password = document.getElementById('password').value;
                const rememberMe = document.getElementById('rememberMe').checked;
                
                // 显示加载状态
                loginText.style.display = 'none';
                loginSpinner.style.display = 'inline-block';
                
                fetch('/api/login/', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                        'X-Requested-With': 'XMLHttpRequest'
                    },
                    body: JSON.stringify({
                        username: username,
                        password: password,
                        remember_me: rememberMe
                    }),
                    credentials: 'include'
                })
                .then(response => {
                    if (!response.ok) {
                        throw new Error('网络响应不正常');
                    }
                    return response.json();
                })
                .then(data => {
                    if (data.status === 'success') {
                        showMessage('登录成功，正在跳转...', 'success');
                        setTimeout(() => {
                            window.location.href = '/index.html';
                        }, 500);
                    } else {
                        showMessage(data.message || '登录失败', 'error');
                    }
                })
                .catch(error => {
                    showMessage('登录失败: ' + error.message, 'error');
                })
                .finally(() => {
                    // 恢复按钮状态
                    loginText.style.display = 'inline-block';
                    loginSpinner.style.display = 'none';
                });
            });
            
            // 页面加载时检查登录状态
            checkAuth();
        });
    </script>
</body>
</html>